(self.webpackChunkmp_webgl = self.webpackChunkmp_webgl || []).push([
  [828],
  {
    33512: (e, t, s) => {
      "use strict";
      s.d(t, {
        Z: () => MeshTrimData,
      });
      var i = s(32770),
        r = s(75256),
        n = s(64781),
        o = s(56247),
        a = s(88512),
        d = s(28719);
      const m = new a.Z("MeshTrimData");
      class MeshTrimData extends i.V {
        constructor(e, t) {
          super(),
            (this.numberOfTrims = 0),
            (this.meshTrimsByFloorIndex = new n.v()),
            (this.meshTrimsById = new n.v()),
            (this.maxNameIndex = -1);
          for (const e of t) {
            const t = e.index,
              s = new r.d();
            this.meshTrimsByFloorIndex.set(
              `$ {
						t
					}`,
              s
            );
          }
          try {
            this.add(...Object.values(e));
          } catch (e) {}
        }
        add(...e) {
          const t = new Set();
          let s = !1;
          if (this.maxNameIndex <= 0) {
            const t = this.meshTrimsById.values.map((e) => e.nameIndex),
              s = t.length ? Math.max(...t) : 0,
              i = e.map((e) => e.nameIndex),
              r = i.length ? Math.max(...i) : 0;
            this.maxNameIndex = Math.max(s, r);
          }
          if (
            (this.meshTrimsById.atomic(() => {
              this.meshTrimsByFloorIndex.atomic(() => {
                for (const i of e) {
                  this.meshTrimsByFloorIndex.has(`$ {
								i.floorIndex
							}`) ||
                    this.meshTrimsByFloorIndex.set(
                      `$ {
								i.floorIndex
							}`,
                      new r.d()
                    );
                  const e = this.meshTrimsByFloorIndex.get(`$ {
								i.floorIndex
							}`);
                  e.length < o.t
                    ? (-1 === i.nameIndex &&
                        ((i.nameIndex = this.maxNameIndex + 1),
                        (this.maxNameIndex = i.nameIndex)),
                      e.push(i),
                      this.meshTrimsById.set(i.id, i),
                      t.add(i.floorIndex))
                    : (m.debugWarn(
                        "Trims exceed floor limit (trimId, floorIndex):",
                        i.id,
                        i.floorIndex
                      ),
                      (s = !0));
                }
              });
            }),
            t.forEach((e) => {
              const t = this.meshTrimsByFloorIndex.get(`$ {
						e
					}`);
              this.sortList(t), this.reassignIndexes(t);
            }),
            (this.numberOfTrims = this.meshTrimsById.length),
            this.commit(),
            s)
          )
            throw new d.M("Exceeding max trims");
        }
        delete(...e) {
          const t = new Set();
          this.meshTrimsByFloorIndex.atomic(() => {
            for (const s of e) {
              const e = this.meshTrimsByFloorIndex.get(`$ {
							s.floorIndex
						}`),
                i = e.indexOf(s);
              if (i >= 0) {
                (e.splice(i, 1)[0].enabled = !1),
                  t.add(s.floorIndex),
                  s.nameIndex === this.maxNameIndex && this.maxNameIndex--;
              } else m.error("Could not delete mesh trim:" + s.id);
            }
          }),
            t.forEach((e) => {
              const t = this.meshTrimsByFloorIndex.get(`$ {
						e
					}`);
              this.reassignIndexes(t);
            }),
            this.meshTrimsById.atomic(() => {
              e.forEach((e) => {
                this.meshTrimsById.delete(e.id);
              });
            }),
            e.length > 1 && (this.maxNameIndex = -1),
            (this.numberOfTrims = this.meshTrimsById.length),
            this.commit();
        }
        getTrimById(e) {
          return this.meshTrimsById.get(e);
        }
        getTrim(e, t) {
          return this.meshTrimsByFloorIndex.has(`$ {
					e
				}`)
            ? this.meshTrimsByFloorIndex
                .get(
                  `$ {
					e
				}`
                )
                .get(t)
            : null;
        }
        getTrimsForFloor(e) {
          return this.meshTrimsByFloorIndex.has(`$ {
					e
				}`)
            ? this.meshTrimsByFloorIndex
                .get(
                  `$ {
					e
				}`
                )
                .values()
            : [];
        }
        reassignIndexes(e) {
          e.forEach((e, t) => {
            e.index = t;
          });
        }
        sortList(e) {
          e.sort((e, t) => e.index - t.index);
        }
      }
    },
    28719: (e, t, s) => {
      "use strict";
      s.d(t, {
        M: () => TooManyTrimsError,
      });
      var i = s(31102);
      class TooManyTrimsError extends i.y {
        constructor(e) {
          super(e), (this.name = "TooManyTrimsError");
        }
      }
    },
    97665: (e, t, s) => {
      "use strict";
      s.r(t),
        s.d(t, {
          default: () => MeshTrimDataModule,
        });
      var i = s(47724),
        r = s(39729),
        n = s(57361),
        o = s(71194),
        a = s(27326),
        d = s(12040),
        m = s(33394),
        h = s(62330),
        l = s(13789),
        c = s(88512),
        u = s(33512);
      class CollectionSerializer {
        constructor(e) {
          this.config = e;
        }
        serialize(e) {
          const { serializer: t } = this.config;
          if (!e || !t) return null;
          const s = {};
          for (const i in e) {
            const r = t.serialize(e[i]);
            r && (s[i] = r);
          }
          return s;
        }
        deserialize(e) {
          const { deserializer: t } = this.config;
          if (!e || !t) return {};
          const s = {};
          for (const i in e) {
            const r = t.deserialize(e[i]);
            r && (s[i] = r);
          }
          return s;
        }
      }
      var x = s(38330),
        p = s(19674),
        I = s(31879),
        y = s(23573),
        T = s(10757);
      class MeshTrim extends y.T {
        constructor(e, t, s, i, r, n, o = new Date(), a = new Date(), d, m, h) {
          super(),
            (this.position = e),
            (this.scale = t),
            (this.rotation = s),
            (this.enabled = r),
            (this.floorIndex = n),
            (this.created = o),
            (this.modified = a),
            (this.id =
              d ||
              `$ {
					this.floorIndex
				}` + (0, T.O1)(11)),
            (this.index = i),
            (this.name = m),
            (this.nameIndex = void 0 === h ? -1 : h);
        }
        get sid() {
          return this.id;
        }
      }
      const f = new c.Z("JsonStoreMeshTrimDeserializer"),
        g = [
          {
            path: ["position", "x"],
            type: "number",
          },
          {
            path: ["position", "y"],
            type: "number",
          },
          {
            path: ["position", "z"],
            type: "number",
          },
          {
            path: ["scale", "x"],
            type: "number",
          },
          {
            path: ["scale", "y"],
            type: "number",
          },
          {
            path: ["scale", "z"],
            type: "number",
          },
          {
            path: ["rotation", "x"],
            type: "number",
          },
          {
            path: ["rotation", "y"],
            type: "number",
          },
          {
            path: ["rotation", "z"],
            type: "number",
          },
          {
            path: ["rotation", "w"],
            type: "number",
          },
          {
            path: ["index"],
            type: "number",
          },
          {
            path: ["enabled"],
            type: "boolean",
          },
          {
            path: ["floorIndex"],
            type: "number",
          },
          {
            path: ["id"],
            type: "string",
          },
          {
            path: ["created"],
            type: "string",
          },
          {
            path: ["modified"],
            type: "string",
          },
        ];
      class JsonStoreMeshTrimDeserializer {
        constructor() {
          this.deserialize = (e) => {
            if (!this.isValid(e))
              return (
                f.debug("Unable to deserialize invalid mesh trim data", e), null
              );
            const {
              position: t,
              scale: s,
              rotation: i,
              index: r,
              enabled: n,
              floorIndex: o,
              created: a,
              modified: d,
              id: m,
              name: h,
              nameIndex: l,
            } = e;
            return new MeshTrim(
              p.ep.fromVisionVector(t),
              p.ep.fromVisionVector(s),
              p.ep.fromVisionQuaternion(i),
              r,
              n,
              o,
              (0, I.p)(a),
              (0, I.p)(d),
              m,
              h,
              l
            );
          };
        }
        isValid(e) {
          return (
            !(!e || "object" != typeof e) &&
            g.every((t) => this.hasRequiredField(e, t))
          );
        }
        hasRequiredField(e, t) {
          try {
            return (
              typeof t.path.reduce((s, i) => {
                if ("object" == typeof s && null !== s) return s[i];
                throw new Error(`data $ {
							JSON.stringify(e)
						}
						must be addressable by $ {
							t.path.join(".")
						}
						with a value of type $ {
							t.type
						}`);
              }, e) === t.type
            );
          } catch (e) {
            return f.debug(e), !1;
          }
        }
      }
      var M = s(87324);
      class JsonStoreMeshTrimSerializer {
        serialize(e) {
          if (!e) return null;
          const {
            position: t,
            scale: s,
            rotation: i,
            index: r,
            enabled: n,
            floorIndex: o,
            created: a,
            modified: d,
            id: m,
            name: h,
            nameIndex: l,
          } = e;
          return {
            position: (0, M.m)(p.ep.toVisionVector(t)),
            scale: (0, M.m)(p.ep.toVisionVector(s)),
            rotation: (0, M.J5)(p.ep.toVisionQuaternion(i)),
            index: r,
            enabled: n,
            floorIndex: o,
            created: (0, I.U)(a),
            modified: (0, I.U)(d),
            id: m,
            name: h,
            nameIndex: l,
          };
        }
      }
      class JsonMeshTrimStore extends x.MU {
        constructor(e, t, s) {
          const i = new JsonStoreMeshTrimDeserializer(),
            r = new JsonStoreMeshTrimSerializer(),
            n = new CollectionSerializer({
              deserializer: i,
              serializer: r,
            });
          super({
            queue: e,
            path: `$ {
						t
					}
					/api/v1 / jsonstore / model / trims / $ {
						s
					}`,
            batchUpdate: !0,
            deserialize: (e) => n.deserialize(e),
            serialize: (e) => n.serialize(e),
          });
        }
      }
      var b = s(17386);
      class CreateMeshTrimCommand extends b.m {
        constructor(e) {
          super(), (this.payload = e), (this.id = "CREATE_MESH_TRIM");
        }
      }
      class DeleteMeshTrimCommand extends b.m {
        constructor(e) {
          super(), (this.payload = e), (this.id = "DELETE_MESH_TRIM");
        }
      }
      var w = s(28719);
      const { TRIM: B } = l.Z.WORKSHOP,
        E = new c.Z("mesh-trim-data-module");
      class MeshTrimDataModule extends i.Y {
        constructor() {
          super(...arguments),
            (this.name = "trim_data"),
            (this.createMeshTrim = async (e) => {
              try {
                this.data.add(e);
              } catch (e) {
                if (e instanceof w.M) {
                  const e = B.MAX_TRIMS_ERROR_MESSAGE;
                  this.engine.commandBinder.issueCommand(
                    new m.I(e, {
                      throttle: 0,
                      type: d.N.ERROR,
                    })
                  );
                }
              }
            }),
            (this.deleteMeshTrim = async (e) => {
              this.data.delete(e);
            }),
            (this.save = async () => {
              const e = this.monitor.getDiffRecord();
              if ((this.monitor.clearDiffRecord(), !e.length)) return;
              const t = {};
              for (const s of e)
                switch (s.action) {
                  case o.KI.added:
                  case o.KI.updated:
                    t[s.index] = this.data.getTrimById(s.index);
                    break;
                  case o.KI.removed:
                    t[s.index] = null;
                }
              try {
                await this.store.update(t);
              } catch (e) {
                E.debug("error when writing to json storage"), E.debug(e);
                const t = B.UNABLE_TO_SAVE_CHANGES_ERROR_MESSAGE;
                this.engine.commandBinder.issueCommand(
                  new m.I(t, {
                    throttle: 30,
                    type: d.N.ERROR,
                  })
                );
              }
            }),
            (this.onMeshTrimsChanged = (0, h.P)(this.save, 1e3));
        }
        async init(e, t) {
          this.engine = t;
          const s = (await t.market.waitForData(a.c)).floors.getOrderedValues();
          this.store = new JsonMeshTrimStore(e.queue, e.baseUrl, e.modelId);
          let i = {};
          try {
            i = (await this.store.read()) || {};
          } catch (e) {
            E.debug("error when reading from json storage"), E.debug(e);
          }
          (this.data = new u.Z(i, s)),
            (this.monitor = new n.c(this.data.meshTrimsById, {
              aggregationType: r.E.Immediate,
            })),
            t.market.register(this, u.Z, this.data),
            this.bindings.push(
              t.commandBinder.addBinding(
                CreateMeshTrimCommand,
                this.createMeshTrim
              ),
              t.commandBinder.addBinding(
                DeleteMeshTrimCommand,
                this.deleteMeshTrim
              )
            ),
            this.monitor.onChanged(this.onMeshTrimsChanged);
        }
      }
    },
  },
]);
